package com.dameng.work.controller;


import com.alibaba.fastjson.JSON;
import com.dameng.work.pojo.GOOD;
import com.dameng.work.pojo.SHELL;
import com.dameng.work.service.GOODService;
import com.dameng.work.service.SHELLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class GOODController {
    @Autowired
    private GOODService gOODService;


    @RequestMapping("/findAllGood")
    @ResponseBody
    public String findAllGood(){

        List<GOOD> findAllList = gOODService.findAllList();

        Map<String, Object> returnMap = new HashMap<>();
        returnMap.put("state","1" );
        returnMap.put("result",findAllList);
        return  JSON.toJSONString(returnMap);

    }


    @RequestMapping("/InsertGOOD_HW1")
    @ResponseBody
    public String InsertGOOD_HW1() throws IOException {

        GOOD good = new GOOD();




        Map<String, Object> returnMap = new HashMap<>();
        returnMap.put("state","1" );
        returnMap.put("result","syccess");
        return  JSON.toJSONString(returnMap);

    }


    @RequestMapping("/queryGoodList")
    @ResponseBody
    public String queryGoodList() throws IOException {

         GOOD good = new GOOD();


        List<GOOD> goods = gOODService.queryGoodList();

        Map<String, Object> returnMap = new HashMap<>();
        returnMap.put("state","1" );
        returnMap.put("result",goods);
        return  JSON.toJSONString(returnMap);

    }
    @RequestMapping("/queryGoodList1")
    @ResponseBody
    public String queryGoodList1() throws IOException {

        GOOD good = new GOOD();

        for (int i = 0; i < 1000000; i++) {
            List<GOOD> goods = gOODService.queryGoodList();
        }
        List<GOOD> goods = null;

        Map<String, Object> returnMap = new HashMap<>();
        returnMap.put("state","1" );
        returnMap.put("result",goods);
        return  JSON.toJSONString(returnMap);

    }
}
